package com.maven.front.controller.manageArticle;

import com.maven.front.bean.FileUploadResult;
import com.maven.front.bean.Result;
import com.maven.front.dto.EduArticleDto;
import com.maven.front.service.manageArticle.AddArticleService;

import com.maven.front.util.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;


//文章添加模块
@RequestMapping("admin/addarticle")
@RestController
public class AddArticleController {
    @Autowired
    private AddArticleService addArticleService;

    @Autowired
    private FileUploadService fileUploadService;
    //添加文章
    @PostMapping("save")
    public Result save(EduArticleDto eduArticleDto) {
        eduArticleDto.setCreateTime(new Date());
        eduArticleDto.setPublishTime(new Date());
        int res = addArticleService.save(eduArticleDto);


        if(res>0){
            return  new Result(200,"添加成功",res);
        }
        else {
            return new Result(400,"添加失败",null);
        }
    }
    @PostMapping("getfile")
 public FileUploadResult getFile(MultipartFile file){
        return fileUploadService.upload(file);
    }

}
